﻿using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Drive.LiveExcelHost
{
    public class RedisPubSub
    {
        static ConnectionMultiplexer redis;
        static RedisPubSub()
        {
            redis = ConnectionMultiplexer.Connect(RedisConf.connectionString);
        }
        public static Task<long> Publish(string channel, string message)
        {
            var sub = redis.GetSubscriber();
            return sub.PublishAsync(channel, message);
        }

        public static Task Subscribe(string channel, Action<RedisChannel, RedisValue> handler)
        {
            var sub = redis.GetSubscriber();
            return sub.SubscribeAsync(channel, handler);
        }
        public static Task Unsubscribe(string channel, Action<RedisChannel, RedisValue> handler)
        {
            var sub = redis.GetSubscriber();
            return sub.UnsubscribeAsync(channel, handler);
        }
    }
}
